package com.jisf.driver.utils;

import com.alibaba.fastjson.JSONObject;
import com.jisf.driver.entity.po.Course;
import com.jisf.driver.entity.po.DrivingSchoolLog;
import com.jisf.driver.service.ICourseService;
import com.jisf.driver.service.IExamineService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.Date;

/**
 * @Classname TimedTask
 * @Description TODO
 * @Date 2022/5/8 2:58
 * @Created by jisf：【429627912@qq.com】
 */
@Configuration
@EnableScheduling
public class TimedTask {

    @Autowired
    private LogUtil log;

    @Autowired
    private ICourseService iCourseService;

    @Autowired
    private IExamineService iExamineService;

    @Scheduled(cron = "0 0 0/1 * * ?")
    private void removeCompleteCourse(){
        String drivingSchoolLog = JSONObject.toJSONString(new DrivingSchoolLog("系统消息", "删除已完成课程的定时任务开始执行", true));
        log.info(drivingSchoolLog);
        iCourseService.removeCompleteCourse();
    }

    @Scheduled(cron = "0 0 0 * * ?")
    private void updateExamineStage(){
        String drivingSchoolLog = JSONObject.toJSONString(new DrivingSchoolLog("系统消息", "更新考试状态的定时任务开始执行", true));
        log.info(drivingSchoolLog);
        iExamineService.updateExamineStage();
    }

}
